<!DOCTYPE html>



  


<html class="theme-next muse use-motion" lang="zh-Hans">
<head><meta name="generator" content="Hexo 3.8.0">
  <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="baidu-site-verification" content="4OYpSWALtb">
<meta name="theme-color" content="#222">
<script>
    (function(){
        if(''){
            if (prompt('请输入文章密码') !== ''){
                alert('密码错误！');
                history.back();
            }
        }
    })();
</script>

<script>
(function(){
    var bp = document.createElement('script');
    var curProtocol = window.location.protocol.split(':')[0];
    if (curProtocol === 'https') {
        bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';        
    }
    else {
        bp.src = 'http://push.zhanzhang.baidu.com/push.js';
    }
    var s = document.getElementsByTagName("script")[0];
    s.parentNode.insertBefore(bp, s);
})();
</script>


  
  
    
    
  <script src="/lib/pace/pace.min.js?v=1.0.2"></script>
  <link href="/lib/pace/pace-theme-minimal.min.css?v=1.0.2" rel="stylesheet">







<meta http-equiv="Cache-Control" content="no-transform">
<meta http-equiv="Cache-Control" content="no-siteapp">
















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css">







<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css">

<link href="/css/main.css?v=5.1.4" rel="stylesheet" type="text/css">


  <link rel="apple-touch-icon" sizes="180x180" href="/zxmLogo.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/zxmLogo.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/zxmLogo.png?v=5.1.4">






  <meta name="keywords" content="移动web,解决方案,">










<meta name="description" content="一、 移动端web基础1. Pixel px: CSS pixels 逻辑像素，浏览器使用的抽象单位； dt,pt: 设备无关像素； dpr: 设备像素缩放比； 公式： 1px = (dpr)2 * dp">
<meta name="keywords" content="移动web,解决方案">
<meta property="og:type" content="article">
<meta property="og:title" content="进入移动web世界">
<meta property="og:url" content="https://flowing_eyes.gitee.io/flowing_eyes.gitee.io/2019/09/16/进入移动web世界/index.html">
<meta property="og:site_name" content="Lomo | 朱幸民">
<meta property="og:description" content="一、 移动端web基础1. Pixel px: CSS pixels 逻辑像素，浏览器使用的抽象单位； dt,pt: 设备无关像素； dpr: 设备像素缩放比； 公式： 1px = (dpr)2 * dp">
<meta property="og:locale" content="zh-Hans">
<meta property="og:updated_time" content="2019-09-17T09:04:48.805Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="进入移动web世界">
<meta name="twitter:description" content="一、 移动端web基础1. Pixel px: CSS pixels 逻辑像素，浏览器使用的抽象单位； dt,pt: 设备无关像素； dpr: 设备像素缩放比； 公式： 1px = (dpr)2 * dp">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Muse',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":true,"onmobile":true},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="https://flowing_eyes.gitee.io/flowing_eyes.gitee.io/2019/09/16/进入移动web世界/">





  <title>进入移动web世界 | Lomo | 朱幸民</title>
  








</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">Lomo | 朱幸民</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <h1 class="site-subtitle" itemprop="description">on the way</h1>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-主页">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br>
            
            主页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-标签">
          <a href="/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br>
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-分类">
          <a href="/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br>
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-时间轴">
          <a href="/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br>
            
            时间轴
          </a>
        </li>
      

      
        <li class="menu-item menu-item-search">
          
            <a href="javascript:;" class="popup-trigger">
          
            
              <i class="menu-item-icon fa fa-search fa-fw"></i> <br>
            
            搜索
          </a>
        </li>
      
    </ul>
  

  
    <div class="site-search">
      
  <div class="popup search-popup local-search-popup">
  <div class="local-search-header clearfix">
    <span class="search-icon">
      <i class="fa fa-search"></i>
    </span>
    <span class="popup-btn-close">
      <i class="fa fa-times-circle"></i>
    </span>
    <div class="local-search-input-wrapper">
      <input autocomplete="off" placeholder="搜索..." spellcheck="false" type="text" id="local-search-input">
    </div>
  </div>
  <div id="local-search-result"></div>
</div>



    </div>
  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-categories" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="https://flowing_eyes.gitee.io/flowing_eyes.gitee.io/2019/09/16/进入移动web世界/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="Lomo 朱幸民">
      <meta itemprop="description" content>
      <meta itemprop="image" content="/images/headImg.png">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Lomo | 朱幸民">
    </span>

    
      <header class="post-header">

        
        
          <h2 class="post-title" itemprop="name headline">进入移动web世界</h2>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2019-09-16T15:42:00+08:00">
                2019-09-16
              </time>
            

            
              <span class="post-meta-divider">|</span>
            

            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-check-o"></i>
              </span>
              
                <span class="post-meta-item-text">更新于&#58;</span>
              
              <time title="更新于" itemprop="dateModified" datetime="2019-09-17T17:04:48+08:00">
                2019-09-17
              </time>
            
          </span>

          
            <span class="post-category">
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/前端笔记/" itemprop="url" rel="index">
                    <span itemprop="name">前端笔记</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          
             <span id="/2019/09/16/进入移动web世界/" class="leancloud_visitors" data-flag-title="进入移动web世界">
               <span class="post-meta-divider">|</span>
               <span class="post-meta-item-icon">
                 <i class="fa fa-eye"></i>
               </span>
               
                 <span class="post-meta-item-text">阅读次数&#58;</span>
               
                 <span class="leancloud-visitors-count"></span>
             </span>
          

          

          
            <div class="post-wordcount">
              
                
                <span class="post-meta-item-icon">
                  <i class="fa fa-file-word-o"></i>
                </span>
                
                  <span class="post-meta-item-text">字数统计&#58;</span>
                
                <span title="字数统计">
                  1.9k字
                </span>
              

              
                <span class="post-meta-divider">|</span>
              

              
                <span class="post-meta-item-icon">
                  <i class="fa fa-clock-o"></i>
                </span>
                
                  <span class="post-meta-item-text">阅读时长 &asymp;</span>
                
                <span title="阅读时长">
                  7分钟
                </span>
              
            </div>
          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <h2 id="一、-移动端web基础"><a href="#一、-移动端web基础" class="headerlink" title="一、 移动端web基础"></a>一、 移动端web基础</h2><h3 id="1-Pixel"><a href="#1-Pixel" class="headerlink" title="1. Pixel"></a>1. Pixel</h3><ul>
<li>px: CSS pixels 逻辑像素，浏览器使用的抽象单位；</li>
<li>dt,pt: 设备无关像素；</li>
<li>dpr: 设备像素缩放比；</li>
<li>公式： 1px = (dpr)<sup>2</sup> * dp</li>
</ul>
<a id="more"></a>
<p><strong>默认缩放比例：</strong></p>
<table>
<thead>
<tr>
<th style="text-align:center"></th>
<th style="text-align:center">ldpi</th>
<th style="text-align:center">mdpi</th>
<th style="text-align:center">hdpi</th>
<th style="text-align:center">xhdpi</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:center">ppi</td>
<td style="text-align:center">120</td>
<td style="text-align:center">160</td>
<td style="text-align:center">240</td>
<td style="text-align:center">320</td>
</tr>
<tr>
<td style="text-align:center">默认缩放比例</td>
<td style="text-align:center">0.75</td>
<td style="text-align:center">1.0</td>
<td style="text-align:center">1.5</td>
<td style="text-align:center">2.0</td>
</tr>
</tbody>
</table>
<h3 id="2-Viewport"><a href="#2-Viewport" class="headerlink" title="2. Viewport"></a>2. Viewport</h3><p>手机浏览器默认做了两件事</p>
<ol>
<li>页面渲染在了一个默认的viewport;</li>
<li>缩放;</li>
</ol>
<p>那么问题来了，为什么会有一个默认的viewport呢？<br>我们知道，pc端页面，在移动端查看的时候，由于像素不匹配，但是为了能够给用户展现一个比较完整的页面，因此会虚拟出一个viewport出来，在此viewprot上渲染页面。也就是说，最终目的，是<strong>为了排版正确</strong>。<br>但是由于一般默认情况下，给出的viewport像素宽对页面来说是不友好、不规范的，因此我们还需要解决一个规范问题。<br>解决方案：<strong>在head中加一个meta标签</strong><br>格式如下：<br><code>&lt;meta name=&quot;viewport&quot; content=&quot;name=value, name=value&quot;&gt;</code></p>
<h3 id="3-meta标签"><a href="#3-meta标签" class="headerlink" title="3. meta标签"></a>3. meta标签</h3><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">&lt;meta name=<span class="string">"viewport"</span> content=<span class="string">"name=value, name=value"</span>&gt;</span><br><span class="line"><span class="comment">// name = value 对应关系</span></span><br><span class="line">width: device-width;</span><br><span class="line">initial: xx;   <span class="comment">// 设置初始缩放</span></span><br><span class="line">minimum-scale: xx;  <span class="comment">// 最小缩放</span></span><br><span class="line">maxim-scale: xx;    <span class="comment">// 最大缩放</span></span><br><span class="line">user-scalable: no;  <span class="comment">// 用户不可缩放</span></span><br></pre></td></tr></table></figure>
<hr>
<h2 id="二、-高效的移动web布局"><a href="#二、-高效的移动web布局" class="headerlink" title="二、 高效的移动web布局"></a>二、 高效的移动web布局</h2><h3 id="1-flexbox弹性布局"><a href="#1-flexbox弹性布局" class="headerlink" title="1. flexbox弹性布局"></a>1. flexbox弹性布局</h3><ul>
<li><p>flex布局混合排版</p>
<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/* 混合使用flex占比 */</span></span><br><span class="line"><span class="selector-class">.nav</span>&#123;</span><br><span class="line">    <span class="attribute">display</span>: -webkit-flex;</span><br><span class="line">&#125;</span><br><span class="line"><span class="selector-class">.son1</span>&#123;</span><br><span class="line">    <span class="attribute">flex</span>: <span class="number">1</span>;        </span><br><span class="line">&#125;</span><br><span class="line"><span class="selector-class">.son2</span>&#123;</span><br><span class="line">    <span class="attribute">flex</span>: <span class="number">3</span>;</span><br><span class="line">&#125;</span><br><span class="line"><span class="selector-class">.son3</span>&#123;</span><br><span class="line">    <span class="attribute">width</span>: <span class="number">100px</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
</li>
<li><p>flex水平垂直居中</p>
<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="selector-class">.parent</span>&#123;</span><br><span class="line">    <span class="attribute">justify-content</span>: center;</span><br><span class="line">    <span class="attribute">align-items</span>: center;</span><br><span class="line">    <span class="attribute">display</span>: -webkit-flex;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
</li>
</ul>
<h3 id="2-flex兼容性"><a href="#2-flex兼容性" class="headerlink" title="2. flex兼容性"></a>2. flex兼容性</h3><ul>
<li>iOS可以使用最新的flex布局；</li>
<li>Android4.4以下，只能兼容旧版flexbox布局；</li>
<li>Android4.4及以上，可以使用最新的flex布局；</li>
</ul>
<p>表现如下：</p>
<table>
<thead>
<tr>
<th style="text-align:center">新felx布局</th>
<th style="text-align:center">旧flexbox布局</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:center">display: -webkit-flex;</td>
<td style="text-align:center">display: -webkit-flex-box;</td>
</tr>
<tr>
<td style="text-align:center">-weblit-flex: 1;</td>
<td style="text-align:center">-weblit-flex-box: 1;</td>
</tr>
<tr>
<td style="text-align:center">justify-content: center;</td>
<td style="text-align:center">box-pack: center;</td>
</tr>
<tr>
<td style="text-align:center">align-items: center;</td>
<td style="text-align:center">box-align: cneter</td>
</tr>
</tbody>
</table>
<h3 id="3-响应式设计"><a href="#3-响应式设计" class="headerlink" title="3. 响应式设计"></a>3. 响应式设计</h3><p>顾名思义，一套页面，在所有端（pc、超大屏、ipad、手机等）完美运行。随页面宽高变化而改变页面样式，从而适配不同设备。</p>
<h4 id="媒体查询-media"><a href="#媒体查询-media" class="headerlink" title="媒体查询  @media"></a>媒体查询  @media</h4><figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br></pre></td><td class="code"><pre><span class="line">@<span class="keyword">media</span> screen and (max-width: <span class="number">1024px</span>) &#123;</span><br><span class="line">    <span class="selector-tag">body</span>&#123;</span><br><span class="line">        <span class="attribute">background</span>: <span class="number">#eee</span>;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line">@<span class="keyword">media</span> screen and (max-width: <span class="number">980px</span>) &#123;</span><br><span class="line">    <span class="selector-tag">body</span>&#123;</span><br><span class="line">        <span class="attribute">background</span>: green;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line">@<span class="keyword">media</span> screen and (max-width: <span class="number">720px</span>) &#123;</span><br><span class="line">    <span class="selector-tag">body</span>&#123;</span><br><span class="line">        <span class="attribute">background</span>: yellow;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line">@<span class="keyword">media</span> screen and (max-width: <span class="number">640px</span>) &#123;</span><br><span class="line">    <span class="selector-tag">body</span>&#123;</span><br><span class="line">        <span class="attribute">background</span>: skyblue;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line">@<span class="keyword">media</span> screen and (max-width: <span class="number">320px</span>) &#123;</span><br><span class="line">    <span class="selector-tag">body</span>&#123;</span><br><span class="line">        <span class="attribute">background</span>: pink;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line">@<span class="keyword">media</span> screen and (min-width: <span class="number">1025px</span>) &#123;</span><br><span class="line">    <span class="selector-tag">body</span>&#123;</span><br><span class="line">        <span class="attribute">background</span>: darkseagreen;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h4 id="媒体类型"><a href="#媒体类型" class="headerlink" title="媒体类型"></a>媒体类型</h4><ul>
<li>screen： 屏幕</li>
<li>print： 打印机</li>
<li>handhead： 手持设备</li>
<li>all： 通用</li>
</ul>
<h4 id="常用参数说明"><a href="#常用参数说明" class="headerlink" title="常用参数说明"></a>常用参数说明</h4><ul>
<li>width: 视口宽</li>
<li>height: 视口高</li>
<li>device-width: 设备宽</li>
<li>device-height: 设备高</li>
<li>orientation: 检查设备横屏竖屏处向（landscape横，portrait竖）</li>
</ul>
<h4 id="设计点"><a href="#设计点" class="headerlink" title="设计点"></a>设计点</h4><ol>
<li>百分比布局：使切换css不同媒体样式时更加平滑</li>
<li>弹性图片：图片根据盒子百分比，改变盒子宽高即可</li>
<li>重新布局，显示和隐藏：<ul>
<li>同比例缩减元素尺寸</li>
<li>调整页面结构布局</li>
<li>隐藏冗余的元素</li>
</ul>
</li>
</ol>
<h4 id="优劣比较"><a href="#优劣比较" class="headerlink" title="优劣比较"></a>优劣比较</h4><ul>
<li>优点：减少重复开发，一套代码多端兼容</li>
<li>劣势：在极端情况下影响页面性能，含有较多的冗余代码</li>
</ul>
<h3 id="4-移动web特别样式处理"><a href="#4-移动web特别样式处理" class="headerlink" title="4. 移动web特别样式处理"></a>4. 移动web特别样式处理</h3><h4 id="a-高清图片处理"><a href="#a-高清图片处理" class="headerlink" title="a. 高清图片处理"></a>a. 高清图片处理</h4><blockquote>
<p>width: (w_value / dpr)px<br>height: (h_value / dpr)px</p>
</blockquote>
<h4 id="b-1像素边框问题"><a href="#b-1像素边框问题" class="headerlink" title="b. 1像素边框问题"></a>b. 1像素边框问题</h4><p><strong>问题：</strong> Retina屏幕下，1像素问题<br><strong>原因：</strong> 1px使用2dp渲染<br><strong>解决：</strong><br><figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/* 错误案例 */</span></span><br><span class="line"><span class="selector-tag">div</span>&#123;</span><br><span class="line">    <span class="attribute">border-top</span>: <span class="number">0.5px</span>;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">/* 正确案例 */</span></span><br><span class="line"><span class="selector-tag">div</span><span class="selector-pseudo">:before</span>&#123;</span><br><span class="line">    <span class="attribute">border-top</span>: <span class="number">1px</span>;</span><br><span class="line">    <span class="attribute">-webkit-transform</span>: <span class="built_in">scaleY</span>(0.5);</span><br><span class="line">    <span class="attribute">position</span>: absolute;</span><br><span class="line">    <span class="attribute">top</span>: -<span class="number">1px</span>;</span><br><span class="line">    <span class="attribute">left</span>: <span class="number">0</span>;</span><br><span class="line">    <span class="attribute">content</span>: <span class="string">''</span>;</span><br><span class="line">    <span class="attribute">height</span>: <span class="number">1px</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<h4 id="c-相对单位"><a href="#c-相对单位" class="headerlink" title="c. 相对单位"></a>c. 相对单位</h4><ul>
<li>em: 根据父节点的font-size为相对单位</li>
<li>rem: 根据html的font-size为相对单位 <strong><em>（建议使用）</em></strong></li>
</ul>
<p>那么，rem的基值设置为多少比较合适呢？<br>回归到开发中来，我们有一个公式：<br><code>rem = screen.width / x</code><br>例： 320的屏幕，可以设置为font-size=32px，而375的屏幕，设置为37.5px。我们的目的是为了方便计算。</p>
<h4 id="d-文本溢出"><a href="#d-文本溢出" class="headerlink" title="d. 文本溢出"></a>d. 文本溢出</h4><figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/* 单行文本溢出*/</span></span><br><span class="line"><span class="selector-class">.line</span>&#123;</span><br><span class="line">    <span class="attribute">overflow</span>: hidden;</span><br><span class="line">    <span class="attribute">white-space</span>: nowrap;</span><br><span class="line">    <span class="attribute">text-overflow</span>: ellipsis;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">/* 多行文本溢出 */</span></span><br><span class="line"><span class="selector-class">.lines</span>&#123;</span><br><span class="line">    <span class="attribute">display</span>: -webkit-box <span class="meta">!important</span>;</span><br><span class="line">    <span class="attribute">overflow</span>: hidden;</span><br><span class="line">    <span class="attribute">text-overflow</span>: ellipsis;</span><br><span class="line">    <span class="attribute">word-break</span>: break-all;</span><br><span class="line">    <span class="attribute">-webkit-box-orient</span>: vertical;</span><br><span class="line">    -webkit-line-clamp: 2;  // 行数</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h2 id="三、-终端交互优化"><a href="#三、-终端交互优化" class="headerlink" title="三、 终端交互优化"></a>三、 终端交互优化</h2><h3 id="1-300ms延迟问题"><a href="#1-300ms延迟问题" class="headerlink" title="1. 300ms延迟问题"></a>1. 300ms延迟问题</h3><p>在移动端，由于有多重手势操作替代了鼠标操作，因此，为了判断出是点击、双击、触摸移动或者别的手势，iOS系统判断中加了一个300毫秒的延迟：在第一次出发事件300毫秒内再次出发，例如点击，就会被判断为双击。那么为了统一规范，后来在Android系统中也加入了此判定。这就是著名的移动端300ms延迟问题。<br>那么如何解决这个问题呢？<strong>tap</strong>事件处理。<br>什么是tap事件？简而言之，就是通过touch，监听touchstart和tarchend，如果两者间隔较短，例如100ms甚至更短，且起始位置的偏移量极小，控制在几个像素之内，那么就判定为点击事件。如此操作，可以绕过系统300ms的规范，从而在用户体验上做的更优。<br>但我们只有，一般有利就有弊。我们解决掉300ms延迟问题，从而又产生了一个新的问题，就是穿透问题。例如在按钮上有一个蒙层，我们点击蒙层，关闭其蒙层。但是如果在蒙层下面同样有点击事件，那么我们在点击蒙层关闭后，也会触发到下面的事件。那么这种问题的一般解决方案便是关闭蒙层的时候，添加一个300ms的延时，经过300ms延时关闭后，点击不再具有穿透性，巧妙的解决的该穿透问题。但是问题又来了，300ms延时其实对用户体验来讲并不那么友好。因此还是推荐第一种解决方案，不会出现拆东墙补西墙或者说捉襟见肘的问题。当然，如果使用框架库的话，大部分强大的库默认都解决了这个问题，不用开发者再为此操心。</p>
<h3 id="2-touch相关"><a href="#2-touch相关" class="headerlink" title="2. touch相关"></a>2. touch相关</h3><p><strong><em>触摸是移动设备交互的核心事件</em></strong></p>
<h4 id="a-触摸事件"><a href="#a-触摸事件" class="headerlink" title="a. 触摸事件"></a>a. 触摸事件</h4><table>
<thead>
<tr>
<th style="text-align:center">事件</th>
<th style="text-align:center">触发情况</th>
<th style="text-align:center">备注</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:center">touchstart</td>
<td style="text-align:center">手指触摸屏幕触发</td>
<td style="text-align:center">已有手指放在屏幕上则不触发</td>
</tr>
<tr>
<td style="text-align:center">touchmove</td>
<td style="text-align:center">手指在屏幕上滑动</td>
<td style="text-align:center">连续触发</td>
</tr>
<tr>
<td style="text-align:center">touchend</td>
<td style="text-align:center">手指离开屏幕时触发</td>
<td style="text-align:center">/</td>
</tr>
<tr>
<td style="text-align:center">touchcancel</td>
<td style="text-align:center">系统取消touch时触发</td>
<td style="text-align:center">不常用</td>
</tr>
</tbody>
</table>
<h4 id="b-事件属性"><a href="#b-事件属性" class="headerlink" title="b. 事件属性"></a>b. 事件属性</h4><ul>
<li>touches： 跟踪触摸操作的touch对象数组</li>
<li>targetTouches： 特定事件目标的touch对象数组</li>
<li>changeTouches： 上次触摸改变的touch对象数组</li>
</ul>
<h4 id="c-每个touch对象包含属性"><a href="#c-每个touch对象包含属性" class="headerlink" title="c. 每个touch对象包含属性"></a>c. 每个touch对象包含属性</h4><ol>
<li>clientX： 触摸目标在视口中的横坐标</li>
<li>clientY： 触摸目标在视口中的纵坐标</li>
<li>identifier： 标识触摸的唯一id</li>
<li>pageX： 触摸目标在页面中的横坐标（含滚动）</li>
<li>pageY： 触摸目标在页面中的纵坐标（含滚动）</li>
<li>screenX： 触摸目标在屏幕中的横坐标</li>
<li>screenY： 触摸目标在屏幕中的纵坐标</li>
<li>target： 触摸的DOM节点的目标</li>
</ol>
<h4 id="d-相关bug"><a href="#d-相关bug" class="headerlink" title="d. 相关bug"></a>d. 相关bug</h4><p>在Android中，某些版本只会触发一次touchstart和一次touchmove，不会触发touchend。解决方案则是在事件中（touchmove）添加阻止默认事件：<code>event.preventDefault()</code>。但与此同时，要注意随之产生的一个问题，就是组织默认事件后，页面也会随之禁止滚动，因此看情况使用。</p>

      
    </div>
    
    
    
	
	<div>
	  
		<div>
    
        <div style="text-align:center;color: #ccc;font-size:14px;">---本文结束<i class="fa fa-paw"></i>感谢您的阅读---</div>
    
</div>
	  
	</div>
	<div>
		  
			
<div class="my_post_copyright">
  <script src="//cdn.bootcss.com/clipboard.js/1.5.10/clipboard.min.js"></script>
  
  <!-- JS库 sweetalert 可修改路径 -->
  <script type="text/javascript" src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"></script>
  <script src="https://ituac-blog-1252741530.cos.ap-beijing.myqcloud.com/zxm/github/sweetalert.main.js"></script>
  <link rel="stylesheet" type="text/css" href="https://ituac-blog-1252741530.cos.ap-beijing.myqcloud.com/zxm/github/sweetalert.css">

  <p><span>本文标题:</span>进入移动web世界</p>
  <p><span>文章作者:</span>Lomo 朱幸民</p>
  <p><span>发布时间:</span>2019年09月16日 - 15:42:00</p>
  <p><span>最后更新:</span>2019年09月17日 - 17:04:48</p>
  <p><span>原始链接:</span><a href="/2019/09/16/进入移动web世界/" title="进入移动web世界">https://flowing_eyes.gitee.io/flowing_eyes.gitee.io/2019/09/16/进入移动web世界/</a>
    <span class="copy-path" title="点击复制文章链接"><i class="fa fa-clipboard" data-clipboard-text="https://flowing_eyes.gitee.io/flowing_eyes.gitee.io/2019/09/16/进入移动web世界/" aria-label="复制成功！"></i></span>
  </p>
  <p><span>许可协议:</span><i class="fa fa-creative-commons"></i> <a rel="license" href="https://creativecommons.org/licenses/by-nc-nd/4.0/" target="_blank" title="Attribution-NonCommercial-NoDerivatives 4.0 International (CC BY-NC-ND 4.0)">署名-非商业性使用-禁止演绎 4.0 国际</a> 转载请保留原文链接及作者。</p>  
</div>
<script> 
    var clipboard = new Clipboard('.fa-clipboard');
    clipboard.on('success', $(function(){
      $(".fa-clipboard").click(function(){
        swal({   
          title: "",   
          text: '复制成功',   
          html: false,
          timer: 500,   
          showConfirmButton: false
        });
      });
    }));  
</script>

		  
	</div>
    

    
      <div>
        <div style="padding: 10px 0; margin: 20px auto; width: 90%; text-align: center;">
  <div>请作者喝杯咖啡吧~</div>
  <button id="rewardButton" disable="enable" onclick="var qr = document.getElementById('QR'); if (qr.style.display === 'none') {qr.style.display='block';} else {qr.style.display='none'}">
    <span>打赏</span>
  </button>
  <div id="QR" style="display: none;">

    
      <div id="wechat" style="display: inline-block">
        <img id="wechat_qr" src="/images/wechatpay.jpg" alt="Lomo 朱幸民 微信支付">
        <p>微信支付</p>
      </div>
    

    
      <div id="alipay" style="display: inline-block">
        <img id="alipay_qr" src="/images/alipay.jpg" alt="Lomo 朱幸民 支付宝">
        <p>支付宝</p>
      </div>
    

    

  </div>
</div>

      </div>
    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/移动web/" rel="tag"><i class="fa fa-tag"></i> 移动web</a>
          
            <a href="/tags/解决方案/" rel="tag"><i class="fa fa-tag"></i> 解决方案</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2019/09/03/vue构建项目入口文件index-html缓存引发的白屏问题/" rel="next" title="vue构建项目入口文件index.html缓存引发的白屏问题">
                <i class="fa fa-chevron-left"></i> vue构建项目入口文件index.html缓存引发的白屏问题
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2019/09/17/《浮生六记》随笔/" rel="prev" title="《浮生六记》随笔">
                《浮生六记》随笔 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
	
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  
    <div class="comments" id="comments">
    </div>
  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
      <div id="sidebar-dimmer"></div>
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image" src="/images/headImg.png" alt="Lomo 朱幸民">
            
              <p class="site-author-name" itemprop="name">Lomo 朱幸民</p>
              <p class="site-description motion-element" itemprop="description"></p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/archives">
              
                  <span class="site-state-item-count">100</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                <a href="/categories/index.html">
                  <span class="site-state-item-count">3</span>
                  <span class="site-state-item-name">分类</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-tags">
                <a href="/tags/index.html">
                  <span class="site-state-item-count">91</span>
                  <span class="site-state-item-name">标签</span>
                </a>
              </div>
            

          </nav>

          <!--
		  */
		  -->



          
            <div class="links-of-author motion-element">
                
                  <span class="links-of-author-item">
                    <a href="https://github.com/xuan0146" target="_blank" title="GitHub">
                      
                        <i class="fa fa-fw fa-github"></i>GitHub</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="mailto:zxm0146@163.com" target="_blank" title="E-Mail">
                      
                        <i class="fa fa-fw fa-envelope"></i>E-Mail</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="https://www.jianshu.com/u/a708dcdb5061" target="_blank" title="简书">
                      
                        <i class="fa fa-fw fa-book"></i>简书</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="https://weibo.com/u/5094024813" target="_blank" title="微博">
                      
                        <i class="fa fa-fw fa-weibo"></i>微博</a>
                  </span>
                
            </div>
          

          
          

          
          

		  <iframe frameborder="no" border="0" marginwidth="0" marginheight="0" width="298" height="52" src="//music.163.com/outchain/player?type=2&id=756112&auto=1&height=32"></iframe>
		  

          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#一、-移动端web基础"><span class="nav-text">一、 移动端web基础</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#1-Pixel"><span class="nav-text">1. Pixel</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-Viewport"><span class="nav-text">2. Viewport</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3-meta标签"><span class="nav-text">3. meta标签</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#二、-高效的移动web布局"><span class="nav-text">二、 高效的移动web布局</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#1-flexbox弹性布局"><span class="nav-text">1. flexbox弹性布局</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-flex兼容性"><span class="nav-text">2. flex兼容性</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3-响应式设计"><span class="nav-text">3. 响应式设计</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#媒体查询-media"><span class="nav-text">媒体查询  @media</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#媒体类型"><span class="nav-text">媒体类型</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#常用参数说明"><span class="nav-text">常用参数说明</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#设计点"><span class="nav-text">设计点</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#优劣比较"><span class="nav-text">优劣比较</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#4-移动web特别样式处理"><span class="nav-text">4. 移动web特别样式处理</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#a-高清图片处理"><span class="nav-text">a. 高清图片处理</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#b-1像素边框问题"><span class="nav-text">b. 1像素边框问题</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#c-相对单位"><span class="nav-text">c. 相对单位</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#d-文本溢出"><span class="nav-text">d. 文本溢出</span></a></li></ol></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#三、-终端交互优化"><span class="nav-text">三、 终端交互优化</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#1-300ms延迟问题"><span class="nav-text">1. 300ms延迟问题</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-touch相关"><span class="nav-text">2. touch相关</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#a-触摸事件"><span class="nav-text">a. 触摸事件</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#b-事件属性"><span class="nav-text">b. 事件属性</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#c-每个touch对象包含属性"><span class="nav-text">c. 每个touch对象包含属性</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#d-相关bug"><span class="nav-text">d. 相关bug</span></a></li></ol></li></ol></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      


    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; 2019 &mdash; <span itemprop="copyrightYear">2021</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Lomo 朱幸民</span>

  
</div>








<div class="theme-info">
  <div class="powered-by"></div>
  <span class="post-count">博客全站共116k字</span>
</div>

        







        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
          <span id="scrollpercent"><span>0</span>%</span>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  
    <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.4"></script>



  
  

  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  












  

  <script type="text/javascript">
    // Popup Window;
    var isfetched = false;
    var isXml = true;
    // Search DB path;
    var search_path = "search.xml";
    if (search_path.length === 0) {
      search_path = "search.xml";
    } else if (/json$/i.test(search_path)) {
      isXml = false;
    }
    var path = "/" + search_path;
    // monitor main search box;

    var onPopupClose = function (e) {
      $('.popup').hide();
      $('#local-search-input').val('');
      $('.search-result-list').remove();
      $('#no-result').remove();
      $(".local-search-pop-overlay").remove();
      $('body').css('overflow', '');
    }

    function proceedsearch() {
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay"></div>')
        .css('overflow', 'hidden');
      $('.search-popup-overlay').click(onPopupClose);
      $('.popup').toggle();
      var $localSearchInput = $('#local-search-input');
      $localSearchInput.attr("autocapitalize", "none");
      $localSearchInput.attr("autocorrect", "off");
      $localSearchInput.focus();
    }

    // search function;
    var searchFunc = function(path, search_id, content_id) {
      'use strict';

      // start loading animation
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay">' +
          '<div id="search-loading-icon">' +
          '<i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>' +
          '</div>' +
          '</div>')
        .css('overflow', 'hidden');
      $("#search-loading-icon").css('margin', '20% auto 0 auto').css('text-align', 'center');

      $.ajax({
        url: path,
        dataType: isXml ? "xml" : "json",
        async: true,
        success: function(res) {
          // get the contents from search data
          isfetched = true;
          $('.popup').detach().appendTo('.header-inner');
          var datas = isXml ? $("entry", res).map(function() {
            return {
              title: $("title", this).text(),
              content: $("content",this).text(),
              url: $("url" , this).text()
            };
          }).get() : res;
          var input = document.getElementById(search_id);
          var resultContent = document.getElementById(content_id);
          var inputEventFunction = function() {
            var searchText = input.value.trim().toLowerCase();
            var keywords = searchText.split(/[\s\-]+/);
            if (keywords.length > 1) {
              keywords.push(searchText);
            }
            var resultItems = [];
            if (searchText.length > 0) {
              // perform local searching
              datas.forEach(function(data) {
                var isMatch = false;
                var hitCount = 0;
                var searchTextCount = 0;
                var title = data.title.trim();
                var titleInLowerCase = title.toLowerCase();
                var content = data.content.trim().replace(/<[^>]+>/g,"");
                var contentInLowerCase = content.toLowerCase();
                var articleUrl = decodeURIComponent(data.url);
                var indexOfTitle = [];
                var indexOfContent = [];
                // only match articles with not empty titles
                if(title != '') {
                  keywords.forEach(function(keyword) {
                    function getIndexByWord(word, text, caseSensitive) {
                      var wordLen = word.length;
                      if (wordLen === 0) {
                        return [];
                      }
                      var startPosition = 0, position = [], index = [];
                      if (!caseSensitive) {
                        text = text.toLowerCase();
                        word = word.toLowerCase();
                      }
                      while ((position = text.indexOf(word, startPosition)) > -1) {
                        index.push({position: position, word: word});
                        startPosition = position + wordLen;
                      }
                      return index;
                    }

                    indexOfTitle = indexOfTitle.concat(getIndexByWord(keyword, titleInLowerCase, false));
                    indexOfContent = indexOfContent.concat(getIndexByWord(keyword, contentInLowerCase, false));
                  });
                  if (indexOfTitle.length > 0 || indexOfContent.length > 0) {
                    isMatch = true;
                    hitCount = indexOfTitle.length + indexOfContent.length;
                  }
                }

                // show search results

                if (isMatch) {
                  // sort index by position of keyword

                  [indexOfTitle, indexOfContent].forEach(function (index) {
                    index.sort(function (itemLeft, itemRight) {
                      if (itemRight.position !== itemLeft.position) {
                        return itemRight.position - itemLeft.position;
                      } else {
                        return itemLeft.word.length - itemRight.word.length;
                      }
                    });
                  });

                  // merge hits into slices

                  function mergeIntoSlice(text, start, end, index) {
                    var item = index[index.length - 1];
                    var position = item.position;
                    var word = item.word;
                    var hits = [];
                    var searchTextCountInSlice = 0;
                    while (position + word.length <= end && index.length != 0) {
                      if (word === searchText) {
                        searchTextCountInSlice++;
                      }
                      hits.push({position: position, length: word.length});
                      var wordEnd = position + word.length;

                      // move to next position of hit

                      index.pop();
                      while (index.length != 0) {
                        item = index[index.length - 1];
                        position = item.position;
                        word = item.word;
                        if (wordEnd > position) {
                          index.pop();
                        } else {
                          break;
                        }
                      }
                    }
                    searchTextCount += searchTextCountInSlice;
                    return {
                      hits: hits,
                      start: start,
                      end: end,
                      searchTextCount: searchTextCountInSlice
                    };
                  }

                  var slicesOfTitle = [];
                  if (indexOfTitle.length != 0) {
                    slicesOfTitle.push(mergeIntoSlice(title, 0, title.length, indexOfTitle));
                  }

                  var slicesOfContent = [];
                  while (indexOfContent.length != 0) {
                    var item = indexOfContent[indexOfContent.length - 1];
                    var position = item.position;
                    var word = item.word;
                    // cut out 100 characters
                    var start = position - 20;
                    var end = position + 80;
                    if(start < 0){
                      start = 0;
                    }
                    if (end < position + word.length) {
                      end = position + word.length;
                    }
                    if(end > content.length){
                      end = content.length;
                    }
                    slicesOfContent.push(mergeIntoSlice(content, start, end, indexOfContent));
                  }

                  // sort slices in content by search text's count and hits' count

                  slicesOfContent.sort(function (sliceLeft, sliceRight) {
                    if (sliceLeft.searchTextCount !== sliceRight.searchTextCount) {
                      return sliceRight.searchTextCount - sliceLeft.searchTextCount;
                    } else if (sliceLeft.hits.length !== sliceRight.hits.length) {
                      return sliceRight.hits.length - sliceLeft.hits.length;
                    } else {
                      return sliceLeft.start - sliceRight.start;
                    }
                  });

                  // select top N slices in content

                  var upperBound = parseInt('1');
                  if (upperBound >= 0) {
                    slicesOfContent = slicesOfContent.slice(0, upperBound);
                  }

                  // highlight title and content

                  function highlightKeyword(text, slice) {
                    var result = '';
                    var prevEnd = slice.start;
                    slice.hits.forEach(function (hit) {
                      result += text.substring(prevEnd, hit.position);
                      var end = hit.position + hit.length;
                      result += '<b class="search-keyword">' + text.substring(hit.position, end) + '</b>';
                      prevEnd = end;
                    });
                    result += text.substring(prevEnd, slice.end);
                    return result;
                  }

                  var resultItem = '';

                  if (slicesOfTitle.length != 0) {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + highlightKeyword(title, slicesOfTitle[0]) + "</a>";
                  } else {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + title + "</a>";
                  }

                  slicesOfContent.forEach(function (slice) {
                    resultItem += "<a href='" + articleUrl + "'>" +
                      "<p class=\"search-result\">" + highlightKeyword(content, slice) +
                      "...</p>" + "</a>";
                  });

                  resultItem += "</li>";
                  resultItems.push({
                    item: resultItem,
                    searchTextCount: searchTextCount,
                    hitCount: hitCount,
                    id: resultItems.length
                  });
                }
              })
            };
            if (keywords.length === 1 && keywords[0] === "") {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-search fa-5x" /></div>'
            } else if (resultItems.length === 0) {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-frown-o fa-5x" /></div>'
            } else {
              resultItems.sort(function (resultLeft, resultRight) {
                if (resultLeft.searchTextCount !== resultRight.searchTextCount) {
                  return resultRight.searchTextCount - resultLeft.searchTextCount;
                } else if (resultLeft.hitCount !== resultRight.hitCount) {
                  return resultRight.hitCount - resultLeft.hitCount;
                } else {
                  return resultRight.id - resultLeft.id;
                }
              });
              var searchResultList = '<ul class=\"search-result-list\">';
              resultItems.forEach(function (result) {
                searchResultList += result.item;
              })
              searchResultList += "</ul>";
              resultContent.innerHTML = searchResultList;
            }
          }

          if ('auto' === 'auto') {
            input.addEventListener('input', inputEventFunction);
          } else {
            $('.search-icon').click(inputEventFunction);
            input.addEventListener('keypress', function (event) {
              if (event.keyCode === 13) {
                inputEventFunction();
              }
            });
          }

          // remove loading animation
          $(".local-search-pop-overlay").remove();
          $('body').css('overflow', '');

          proceedsearch();
        }
      });
    }

    // handle and trigger popup window;
    $('.popup-trigger').click(function(e) {
      e.stopPropagation();
      if (isfetched === false) {
        searchFunc(path, 'local-search-input', 'local-search-result');
      } else {
        proceedsearch();
      };
    });

    $('.popup-btn-close').click(onPopupClose);
    $('.popup').click(function(e){
      e.stopPropagation();
    });
    $(document).on('keyup', function (event) {
      var shouldDismissSearchPopup = event.which === 27 &&
        $('.search-popup').is(':visible');
      if (shouldDismissSearchPopup) {
        onPopupClose();
      }
    });
  </script>





  

  
  <script src="https://cdn1.lncld.net/static/js/av-core-mini-0.6.4.js"></script>
  <script>AV.initialize("ivrWycPPaTqpUQWlrrynaC9b-gzGzoHsz", "hEXywpn5sGaCnm5zWsMmEu2j");</script>
  <script>
    function showTime(Counter) {
      var query = new AV.Query(Counter);
      var entries = [];
      var $visitors = $(".leancloud_visitors");

      $visitors.each(function () {
        entries.push( $(this).attr("id").trim() );
      });

      query.containedIn('url', entries);
      query.find()
        .done(function (results) {
          var COUNT_CONTAINER_REF = '.leancloud-visitors-count';

          if (results.length === 0) {
            $visitors.find(COUNT_CONTAINER_REF).text(0);
            return;
          }

          for (var i = 0; i < results.length; i++) {
            var item = results[i];
            var url = item.get('url');
            var time = item.get('time');
            var element = document.getElementById(url);

            $(element).find(COUNT_CONTAINER_REF).text(time);
          }
          for(var i = 0; i < entries.length; i++) {
            var url = entries[i];
            var element = document.getElementById(url);
            var countSpan = $(element).find(COUNT_CONTAINER_REF);
            if( countSpan.text() == '') {
              countSpan.text(0);
            }
          }
        })
        .fail(function (object, error) {
          console.log("Error: " + error.code + " " + error.message);
        });
    }

    function addCount(Counter) {
      var $visitors = $(".leancloud_visitors");
      var url = $visitors.attr('id').trim();
      var title = $visitors.attr('data-flag-title').trim();
      var query = new AV.Query(Counter);

      query.equalTo("url", url);
      query.find({
        success: function(results) {
          if (results.length > 0) {
            var counter = results[0];
            counter.fetchWhenSave(true);
            counter.increment("time");
            counter.save(null, {
              success: function(counter) {
                var $element = $(document.getElementById(url));
                $element.find('.leancloud-visitors-count').text(counter.get('time'));
              },
              error: function(counter, error) {
                console.log('Failed to save Visitor num, with error message: ' + error.message);
              }
            });
          } else {
            var newcounter = new Counter();
            /* Set ACL */
            var acl = new AV.ACL();
            acl.setPublicReadAccess(true);
            acl.setPublicWriteAccess(true);
            newcounter.setACL(acl);
            /* End Set ACL */
            newcounter.set("title", title);
            newcounter.set("url", url);
            newcounter.set("time", 1);
            newcounter.save(null, {
              success: function(newcounter) {
                var $element = $(document.getElementById(url));
                $element.find('.leancloud-visitors-count').text(newcounter.get('time'));
              },
              error: function(newcounter, error) {
                console.log('Failed to create');
              }
            });
          }
        },
        error: function(error) {
          console.log('Error:' + error.code + " " + error.message);
        }
      });
    }

    $(function() {
      var Counter = AV.Object.extend("Counter");
      if ($('.leancloud_visitors').length == 1) {
        addCount(Counter);
      } else if ($('.post-title-link').length > 1) {
        showTime(Counter);
      }
    });
  </script>



  

  
<script>
(function(){
    var bp = document.createElement('script');
    var curProtocol = window.location.protocol.split(':')[0];
    if (curProtocol === 'https') {
        bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';        
    }
    else {
        bp.src = 'http://push.zhanzhang.baidu.com/push.js';
    }
    var s = document.getElementsByTagName("script")[0];
    s.parentNode.insertBefore(bp, s);
})();
</script>


  
  

  

  

  

<script src="/live2dw/lib/L2Dwidget.min.js?094cbace49a39548bed64abff5988b05"></script><script>L2Dwidget.init({"log":false,"pluginJsPath":"lib/","pluginModelPath":"assets/","pluginRootPath":"live2dw/","tagMode":false});</script></body>
</html>
